﻿using System;
using System.Text;
using System.Collections.Generic;

namespace Edu.Technion.CSE.OpenUnit4.CollectionsLib
{
    /// <summary>
    /// 
    /// </summary>
    /// <typeparam name="T"></typeparam>
    public class Stack<T> : IStack<T>
    {
        // members

        private System.Collections.Generic.Stack<T> stack;

        // Constructors

        /// <summary>
        /// 
        /// </summary>
        public Stack()
        {
            stack = new System.Collections.Generic.Stack<T>();
        }

        // Public Methods

        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public bool IsEmpty()
        {
            return (stack.Count == 0);
        }

        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public T Pop()
        {
            return stack.Pop();
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="item"></param>
        public void Push(T item)
        {
            stack.Push(item);
        }

        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public T Top()
        {
            return stack.Peek();
        }

        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public override string ToString()
        {
            StringBuilder sb = new StringBuilder("[");
            T[] items = stack.ToArray();
            for (int i = 0; i < items.Length; i++)
            {
                sb.Append(items[i].ToString());
                sb.Append(",");
            }
            sb.Insert(sb.Length - 1, "]");
            return sb.ToString();
        }
    }
}
